let reqUrl = ''
let header = {
  'content-type': 'application/json',
  'accept': 'application/json'
}

let getReq = (url, params, func) => {
  wx.showLoading({
    title: '加载中',
  })
  wx.request({
    url: `${url}`,
    data: { params },
    method: 'GET',
    success: (res) => {
      wx.hideLoading()
      return typeof func === 'function' && func(res)
    },
    fail: (err) => {
      wx.hideLoading()
      return typeof func === 'function' && func(err)
    }
  })
}

let postReq = (url, params, func) => {
  wx.showLoading({
    title: '加载中',
  })
  wx.request({
    url: `${url}`,
    data: params,
    method: 'POST',
    success: (res) => {
      wx.hideLoading()
      return typeof func === 'function' && func(res.data)
    },
    fail: (err) => {
      wx.hideLoading()
      return typeof func === 'function' && func(err)
    }
  })
}

module.exports = {
  getReq,
  postReq
}